package jrain.utils.url;

/**
 * <pre>
 * 作者：489088214@qq.com 
 * 描述：路径处理工具类
 * </pre>
 */
public class UrlUtils {

	/**
	 * 合并路径
	 * @param path1 路径1
	 * @param path2 路径2
	 * @return 合并后字符串
	 */
	public static String joinUrl(String path1, String path2) {
		if (path1 == null || path1.trim().length() == 0) {
			path1 = "";
		}
		path1 = path1.trim();
		if (path2 == null || path2.trim().length() == 0) {
			path2 = "";
		}
		path2 = path2.trim();
		if (path1.length() == 0 && path2.length() == 0) {
			return "";
		} else if (path1.length() != 0 && path2.length() == 0) {
			if (path1.endsWith("/")) {
				path1 = path1.substring(0, path1.length() - 1);
			}
			return path1;
		} else if (path1.length() == 0 && path2.length() != 0) {
			if (path2.endsWith("/")) {
				path2 = path2.substring(0, path2.length() - 1);
			}
			if (path2.startsWith("/")) {
				return path2;
			} else {
				return "/" + path2;
			}
		} else {
			if (!path1.endsWith("/")) {
				path1 = path1 + "/";
			}
			if (path2.endsWith("/")) {
				path2 = path2.substring(0, path2.length() - 1);
			}
			if (path2.startsWith("/")) {
				path2 = path2.substring(1, path2.length());
			}
			return path1 + path2;
		}
	}
}
